package com.xieyingwangluo.yxpart.mapper;

import com.xieyingwangluo.yxpart.entity.WorksheetModel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public interface WorksheetMapper {

    //新增保存

    //@CacheEvict(value="d_user",allEntries = true)
    int add(WorksheetModel worksheet);

    //模糊查询所有
    List<WorksheetModel> selA(WorksheetModel work);

    //根据id获取用户信息
    //@Cacheable(value="d_demo",key="'UserMapper_getById_'+#noid")
    WorksheetModel getById(@Param("noid") String noid);

    //根据登录用户和工作状态查询工作列表
    //工作状态(0已报名，1已录用，2已完工)
    @Select("select * from worksheet where userinfo_id=#{userinfo_id} and state=#{state}")
    List<WorksheetModel> getByState(@Param("userinfo_id") String userinfo_id, @Param("state") int state);

    //根据工作id修改工作状态  (改为录用)
    @Update("update worksheet set state=#{state},record_time=#{record_time} where noid=#{noid}")
    int updS(@Param("noid") String noid, @Param("state") int state, @Param("record_time") Date record_time);

    // 确认完工
    @Update("update worksheet set state=#{state},makespan=#{makespan} where userinfo_id=#{userinfo_id}")
    int updSByUser(@Param("userinfo_id") String userinfo_id, @Param("state") int state, @Param("makespan") Date makespan);

    //更新工作
    int update(WorksheetModel work);

    //根据part_id获取用户信息
    @Select("select * from worksheet where part_id=#{part_id}")
    WorksheetModel getByPaId(@Param("part_id") String part_id);

    //删除工作
    @Delete("delete from worksheet where noid=#{noid}")
    int del(@Param("noid") String noid);

    //根据兼职id和用户信息详情id查询工作信息
    @Select("select * from worksheet where part_id =#{part_id} AND userinfo_id=#{userinfo_id}")
    WorksheetModel getWorkByU(@Param("part_id") String part_id, @Param("userinfo_id") String userinfo_id);
}
